/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package bean;

import entity.Mobile;
import javax.inject.Named;
import javax.enterprise.context.SessionScoped;
import java.io.Serializable;
import java.util.List;
import javax.ejb.EJB;

/**
 *
 * @author TUANNK
 */
@Named(value = "mobile")
@SessionScoped
public class mobileBean implements Serializable {

    public MobileFacadeLocal getMobileFacade() {
        return mobileFacade;
    }

    public void setMobileFacade(MobileFacadeLocal mobileFacade) {
        this.mobileFacade = mobileFacade;
    }
    @EJB
    private MobileFacadeLocal mobileFacade;

    private Mobile curmobile;
    private String message;
    private int min;
    private int max;

    public int getMin() {
        return min;
    }

    public void setMin(int min) {
        this.min = min;
    }

    public int getMax() {
        return max;
    }

    public void setMax(int max) {
        this.max = max;
    }
    public mobileBean() {
        curmobile = new Mobile();
    }

    public Mobile getCurmobile() {
        return curmobile;
    }

    public void setCurmobile(Mobile curmobile) {
        this.curmobile = curmobile;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }
    
    public List<Mobile> getAll() {
        return mobileFacade.findAll();
    }
    
    public String insertMobile() {
        mobileFacade.create(getCurmobile());
        return "index?faces-redirect=true";
    }
    public List<Mobile> searchByPrice() {
        return mobileFacade.searchByPrice(min, max);
    }
    
    public void deleteMobile() {
        mobileFacade.remove(curmobile);
    }
    
    public String updateMobile() {
        mobileFacade.edit(curmobile);
        return "index?faces-redirect=true";
    }
}
